package com.vhall.component.entity.goods.goods;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author guoxin.wang
 * @date 2021/10/22 13:45
 */
@Data
public class GoodsPage<T extends Serializable> implements Serializable {

    private static final long serialVersionUID = -5904550263087447017L;

    /**
     * 数据总量
     */
    @JsonProperty(value = "total")
    private Integer total;

    /**
     * 分页大小
     */
    @JsonProperty(value = "per_page")
    private Integer perPage;

    /**
     * 当前页
     */
    @JsonProperty(value = "page")
    private Integer page;

    /**
     * 最后一页
     */
    @JsonProperty(value = "last_page")
    private Integer lastPage;

    /**
     * 观众端商品入口开关，0=关闭，1=开启
     */
    @JsonProperty(value = "goods_switch")
    private Integer goodsSwitch;

    /**
     * 当前页数据
     */
    @JsonProperty(value = "list")
    private List<T> data;

    public GoodsPage(Integer index, int size, int total, List<T> data, Integer goodsSwitch) {
        this.total = total;
        this.perPage = size;
        this.page = index;
        this.lastPage = Math.max((int) Math.ceil(total / (double) size), 1);
        this.data = data;
        this.goodsSwitch = goodsSwitch;
    }

}
